package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.ServiceRecordBean;
import com.sx.zongzhi.bean.ServiceSearchBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IServiceRecordView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *获取服务记录
 */
public class ServiceRecordPest {

    private IServiceRecordView recordView;

    public ServiceRecordPest(IServiceRecordView recordView) {
        this.recordView=recordView;
    }

    /**
     *
     * @param orgId 组织机构编码
     * @param bean 筛选条件
     */
    public void getServiceRecordList(String orgId,ServiceSearchBean bean
            ,int page,int rows){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("serviceRecordVo.organization.id", orgId);
        if (bean!=null) {
            map.put("serviceRecordVo.members[0].id", bean.getMembersId());
            map.put("serviceRecordVo.objects[0].id", bean.getObjectsID());
            map.put("serviceRecordVo.occurPlace", bean.getOccurPlace());
            map.put("serviceRecordVo.serviceJoiners", bean.getServiceJoiners());
            map.put("serviceRecordVo.occurDateStart", bean.getOccurDateStart());
            map.put("serviceRecordVo.occurDateEnd", bean.getOccurDateEnd());
        }
        map.put("page", page);
        map.put("rows", rows);
        new ApiManager().getServiceRecordList(map, new BaseCallBack<BaseResult<ServiceRecordBean>>() {
            @Override
            public void onSuccess(BaseResult<ServiceRecordBean> response) {
                recordView.getServiceRecordList(response.getData());
            }
            @Override
            public void onFailures(String message) {
                recordView.showError(message);
            }
        });
    }

}
